package org.sy.lab.多线程基础._3_同步辅助类._5_Exchanger交换者;

import java.util.concurrent.Exchanger;
import java.util.concurrent.TimeUnit;

public class Account2 implements Runnable {

	private Exchanger<Integer> exchanger;
	
	public Account2(Exchanger<Integer> exchanger) {
		this.exchanger = exchanger;
	}
	
	@Override
	public void run() {
		try {
			TimeUnit.SECONDS.sleep(5);
			System.out.println(Thread.currentThread().getName() + "已出账");
			
			Integer account = exchanger.exchange(666);
			System.out.println(Thread.currentThread().getName() + "对方金额：" + account);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
